79

Build Your Own Remote Control

79

function called GetAsyncKeyState that is available for use but has to be declared

upfront (see step 1 code). The code below covers some of the basic navigations that

can be done by the user near the laptop, without using the smartphone. The letter “N”,

Right or Down keys take you to next slide. The letter “P”, Up, or Left keys take you

to the previous slide. The “X” key is to exit the program.

STEP 3

Sub ManualInterrupt()

Const VK_​CONTROL =​ &H11, VK_​LEFT =​ &H25, VK_​UP =​ &H26, VK_​

RIGHT =​ &H27, VK_​DOWN =​ &H28

Const VK_​0 =​ &H30, VK_​1 =​ &H31, VK_​2 =​ &H32, VK_​3 =​ &H33, VK_​4 =​ &H34

Const VK_​5 =​ &H35, VK_​6 =​ &H36, VK_​7 =​ &H37, VK_​8 =​ &H38, VK_​9 =​ &H39

Const VK_​A =​ &H41, VK_​B =​ &H42, VK_​C =​ &H43, VK_​D =​ &H44, VK_​

E =​ &H45

Const VK_​F =​ &H46, VK_​G =​ &H47, VK_​H =​ &H48, VK_​I =​ &H49, VK_​J =​ &H4A

Const VK_​K =​ &H4B, VK_​L =​ &H4C, VK_​M =​ &H4D, VK_​N =​ &H4E, VK_​

O =​ &H4F

Const VK_​P =​ &H50, VK_​Q =​ &H51, VK_​R =​ &H52, VK_​S =​ &H53, VK_​T =​ &H54

Const VK_​U =​ &H55, VK_​V =​ &H56, VK_​W =​ &H57, VK_​X =​ &H58, VK_​

Y =​ &H59, VK_​Z =​ &H5A

Const VK_​ENTER =​ &HD

If GetAsyncKeyState(VK_​X) <> 0 Then

    ‘ MsgBox (“forced exit”)

    ForcedExit =​ 1

    MsgBox (“Forced”)

End If

If GetAsyncKeyState(VK_​DOWN) <> 0 Then

    NextSlide

End If

If GetAsyncKeyState(VK_​RIGHT) <> 0 Then

    NextSlide

End If

If GetAsyncKeyState(VK_​UP) <> 0 Then

    PreviousSlide

End If

If GetAsyncKeyState(VK_​LEFT) <> 0 Then

    PreviousSlide

End If

If GetAsyncKeyState(VK_​P) <> 0 Then

    PreviousSlide

End If

If GetAsyncKeyState(VK_​N) <> 0 Then

    NextSlide

End If

End Sub

Note—​VBA code in powerpoint is slightly different than in excel—​some com­

mands and functions used in excel do not work in powerpoint.